<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
	<title>{$caption}</title>
	<link rel="stylesheet" href="__PUBLIC__/User/css/weui.css"/>
	<link rel="stylesheet" href="__PUBLIC__/User/css/example.css"/>
	<link rel="stylesheet" href="__PUBLIC__/User/css/swiper.min.css">
	<script src="__PUBLIC__/User/newjs/jquery.js"></script>
	<script src="__PUBLIC__/User/js/swiper.min.js"></script>
	<script src="__PUBLIC__/User/js/dom_tool.js"></script>
    <script src="__PUBLIC__/User/js/layer.js"></script>
	<script src="<?php echo $dic;?>"></script>
	<script src="<?php echo $layer;?>"></script>
	<!--树形结构-->
	<link rel="stylesheet" href="__PUBLIC__/User/css/zTreeStyle.css">
	<link rel="stylesheet" href="__PUBLIC__/User/css/treeDemo.css" type="text/css">
	<script src="__PUBLIC__/User/newjs/jquery.ztree.core.js"></script>
	<script src="__PUBLIC__/User/newjs/myztree.js"></script>
    <!--文件上传-->
    <!--<link rel="stylesheet" href="__PUBLIC__/User/css/jquery.filer.css">-->
    <!--<link rel="stylesheet" href="__PUBLIC__/User/css/jquery.filer-dragdropbox-theme.css">-->
    <!--<link rel="stylesheet" href="__PUBLIC__/User/css/custom.css">-->
    <!--文件上传插件-->
    <!--<script src="__PUBLIC__/User/newjs/jquery.filer.min.js" type="text/javascript"></script>-->
    <!-- 二次定义weui样式开始 -->
	<style>
		.weui-cell__hd{
			width:40%;
			padding:0px;
		}
		.weui-cell{
			width:60%;
		}
		.weui-cell_vcode{
			width:100%;
		}
		.weui-label{
			width:140px;
			overflow: hidden;
		}
		.operation_div,.operation_div_2{
			padding:18px;
		}
		.weui-input{
			padding-left:12px;
		}
        .ztree * {
            font-size: 18px;
        }
		.file_input {
			width:90%;
            border: 0;
            outline: 0;
            -webkit-appearance: none;
            background-color: transparent;
            font-size: inherit;
            color: inherit;
            height: 1.41176471em;
            line-height: 1.41176471;
		}
        .filelable{
            margin-left:15px;
            line-height: 1.41176471;
            font-size: 18px;
        }
        .file_info{
            margin-left:50px;
        }
        span{
            margin-right:10px;
        }

        /*.operation_div_2 input{*/
        /*width:23%;*/
        /*margin-right: 2%;*/
        /*display: inline;*/
        /*}*/

	</style>
<!-- 二次定义weui样式结束 -->
<script>
	//初始化是否审批状态标记
	var menu = '{$menu}';  //子集名称
	var uuid = '{$uuid}';  //员工编码
	var sj_info = eval({$sj_info}); //时间验证配置
	var file_zd = eval({$file_zd});  //附件字段

	function aa(data) {
		var resolt = null;
		$.ajax({
			url: '__MODULE__/Info/checkWyx',
			type: 'post',
			data: data,
			async: false,
			success: function (e) {
				resolt = e;
			}
		});
		return resolt;
	}
	$(function(){
		var json = eval({$info});  //子集数据
		var kz_json = eval({$kz_info});  //扩展配置数据
		//console.log(kz_json);return;
		var change_item = '{$change_item}'; //已在审核中的子集
		//判断是否为可拓展子集
		var is_extension = {$is_extension};
		if(is_extension==0){
			var data = {
				name: menu,
				action: '__MODULE__/Info/edit',
				method: 'post',
				json: json.sublist,
				dic: dic,
				layer_js: layer_js,
				kz_json: kz_json,
				change_item: change_item,
				sp_type:json.sp_type,
				reason:json.reason
			};
			formStart(data);
		}else{
			var data = {
				name: menu,
				action: '__MODULE__/Info/edit',
				method: 'post',
				json: json.sublist,
				value: json.subvalue,
				dic: dic,
				layer_js: layer_js,
				kz_json: kz_json,
				change_item: change_item
			};
			formStart_sub(data);
		}
		//检测表单提交数据合法性
		$('.btn-default').click(function (){
			if(menu == 'BO_CASC_HR_YGRS'){
				//检测照片的大小和类型
				var obj = document.getElementById('inputFile_0');
				var resolt = fileZpSize(obj);
				if(!resolt){
					return false;
				}
			}
			//检测附件的大小和类型
			var tob = 0;
			$('.file_input').each(function(){
				var fjresolt = fileFJSize($(this)[0]);
				if(!fjresolt){
					tob++;
				}
			});
			if(tob){
				return false;
			}
			//验证时间规则
			for(var i in sj_info){
				var bj_val = $('input[name='+i+']').val();
				var bj_name = $('input[name='+i+']').parent().prev().find('label').text();
				if(bj_name.indexOf('*')>-1){
					bj_name = bj_name.substr(0, bj_name.length - 1);
				}
				var b_bj_val = $('input[name='+sj_info[i].max+']').val();
				var b_bj_name = $('input[name='+sj_info[i].max+']').parent().prev().find('label').text();
				if(b_bj_name.indexOf('*')>-1){
					b_bj_name = b_bj_name.substr(0, b_bj_name.length - 1);
				}
				if(sj_info[i].method == 1){
					if(bj_val && b_bj_val && bj_val <= b_bj_val){
						layer.alert(bj_name+' 不能小于或等于 '+b_bj_name);
						return false;
					}
				}else if(sj_info[i].method == 2){
					if(bj_val && b_bj_val && bj_val < b_bj_val){
						layer.alert(bj_name+' 不能小于 '+b_bj_name);
						return false;
					}
				}
			}
		});

		//唯一性验证
		$('.checkWyx').change(function () {
			var self = $(this);
			var val = $(this).val();
			var zd_name = $(this).attr('name');
			var form = $(this).parents('form');

			if (val == '是') {
				var caption = $(this).parent().prev().find('label').text();
				caption = caption.substr(0, caption.length - 1);
				var offset = form.find('input[name=_offset_id]').val();
				var data = {uuid: uuid, item: menu, name: zd_name, offset: offset};
				var resolot = aa(data);
				if (resolot.type == 2) {
					var text = '字段 ' + caption + ' 已经存在唯一值,您是保留当前值,更改其他该字段的值,还是更改当前字段的值该为否,其他记录值不变?';
					layer.confirm(text, {
						btn: ['保留', '不保留'] //按钮
					}, function () {
						var zj_input = '<input type="hidden" name="upd-' + zd_name + '" value="'+resolot.key+'">';
						form.append(zj_input);
						layer.msg(caption + '的值为是,将更改其他记录值!');
					}, function () {
						self.val('否');
						layer.msg(caption + '的值改为否,其他记录此字段值不变!');
					});
				}
			}
		});

		//已在审核的子集不能输入
		if(change_item.indexOf(menu) > -1){
            $('.weui-input').attr('disabled',true);

			$('select').attr('disabled',true);
			//附件不能点击删除和上传
			$('.removefile').hide();
			$('.clonebtn').html('　');
		}

        //点击取消按钮隐藏alert提示
		$('#dialog2_but').bind('click',function(){
		    $('#dialog2').hide();
		});
		//监听返回首页按钮 返回上一页
		$('.callback_button').bind('click',function(){
		    location.href = "/User/Index/index";
		});
		//节点滑动特特效
		var swiper = new Swiper('.swiper-container', {
		    pagination: '.swiper-pagination',
		    paginationClickable: true,
		});
		//监听新增子集事件
		$('.add_info').bind('click',function(){
		    //获取子集名称
		    var tablename = $('input[name=table_name]').val();
            //alert(tablename);return;
		    var url = "/User/Info/addInfo/menu/"+tablename;
		    location.href = url;
		});
		
		//监听删除子集数据事件
		$('.sub_del').bind('click',function(){
		    //记录数据坐标
		    var offset = $(this).attr('_offset_id');
		    //记录子集名称
		    var tablename = $('input[name=table_name]').val();
			layer.confirm('确定要删除此条记录吗?',{
				btn : ['确定','取消']
			},function(){
				location.href = "__MODULE__/Info/delInfo/tablename/" + tablename + "/id/" + offset;
			});
		});

        //初始化树形结
        for(var i in layer_id){
            $("#"+i).on("click",{i: i},function (e) {
                var q=0;
                $.fn.zTree.init($("#tree"), setting,layer_js[layer_id[e.data.i]]);
                showMenu($(this));
            });
        }
        //重新调整树形结构宽度
        $(window).resize(function () {
            $("#menuContent").hide();
            $("#menuContent ul").width(($("#inputText_2").parent('div').width()-50)+"px");
        });
        $("#menuContent ul").width($("#inputText_2").parent('div').width()+"px");

    });
    /****************** 附件上传*******************************/
    //克隆上传文件按钮
    function add_file(e){
        var pNode=$(e).parents('.file_warp');
        pNode.parent('div').append(pNode.clone().children('input').val('').end()).children('.file_warp').eq(0).siblings().find('.file_add').attr("class",'file_remove').find('a').attr("onclick",'remove_file(this)').html("[-]");
    }
    //删除文件上传按钮
    function remove_file(e) {
        $(e).parents('.file_warp').remove();
    }
    //删除文件
    function  remove_result(e) {
        var self = $(e);
        var filename = $(e).attr('filename');
        var offset = $(e).attr('offset');
        var zd_name = $(e).attr('zd_name');
        layer.confirm('确定要删除此附件吗?',{
            btn : ['确定','取消']
        },function(){
            $.ajax({
                url : '/Pc/Common/removeFile',
                type : 'post',
                data : {uuid:uuid,menu:menu,offset:offset,zd_name:zd_name,filename:filename},
                async : false,
                success : function(a){
                    if(a){
                        self.parents('.p1').remove();
                        layer.msg('删除文件成功!');
                    }else{
                        layer.msg('删除文件失败!');
                    }
                }
            });
        },function(){});
    }
    /*******************************************检测照片和附件的大小和类型*************************************************/
    //检测照片
    function fileZpSize(obj){
        if(!obj.value){
            return true;
        }
        var photoExt = obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();//获得文件后缀名
        var filetype = '.jpg,.gif,.png,.jpeg';
        //alert(filetype.indexOf(photoExt));return false;
        if(filetype.indexOf(photoExt)<0){
            layer.alert("上传的照片只支持jpg,gif,png,jpeg的格式!");
            return false;
        }
        var fileSize = 0;
        var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
        if (isIE && !obj.files) {
            var filePath = obj.value;
            var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
            var file = fileSystem.GetFile (filePath);
            fileSize = file.Size;
        }else {
            fileSize = obj.files[0].size;
        }
        fileSize=Math.round(fileSize/1024*100)/100; //单位为KB
        if(fileSize >= 2000){
            layer.alert("上传照片最大尺寸为2M，请重新上传!");
            return false;
        }
        return true;
    }
    //检测附件
    function fileFJSize(obj,tob){
        if(!obj.value){
            return true;
        }
        var photoExt = obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();//获得文件后缀名
        var filetype = '.jpg,.gif,.png,.jpeg,.xls,.xlsx,.doc,.docx,.ppt,.pptx';
        //alert(filetype.indexOf(photoExt));return false;
        if(filetype.indexOf(photoExt)<0){
            tob++;
            layer.alert("上传附件的只支持'jpg', 'gif', 'png', 'jpeg','xls','xlsx','doc','docx','ppt','pptx'的格式!");
            return false;
        }
        var fileSize = 0;
        var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
        if (isIE && !obj.files) {
            var filePath = obj.value;
            var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
            var file = fileSystem.GetFile (filePath);
            fileSize = file.Size;
        }else {
            fileSize = obj.files[0].size;
        }
        fileSize=Math.round(fileSize/1024*100)/100; //单位为KB
        if(fileSize >= 2000){
            tob++;
            layer.alert("上传的附件大小超过2M，请重新上传!");
            return false;
        }
        return true;
    }
</script>
</head>
<body>
    <div>
        <div class="content_wrap"></div>
        <div id="menuContent" class="menuContent" style=" display:none;position: absolute;">
            <ul id="tree" class="ztree" style="margin-top:0; width:370px; height: 300px;"></ul>
        </div>
    </div>
	<div id="dialog3" style="display:none;">
	    <div class="weui-mask"></div>
        <div class="weui-dialog">
            <div class="weui-dialog__hd"><strong class="weui-dialog__title">操作提示</strong></div>
            <div class="weui-dialog__bd">确定要提交吗？
            </div>
            <div class="weui-dialog__ft">
                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default">取消</a>
                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">确定</a>
            </div>
        </div>
	</div>
	<div id="dialog1" style="display:none;">
	    <div class="weui-mask"></div>
        <div class="weui-dialog">
            <div class="weui-dialog__hd"><strong class="weui-dialog__title">操作提示</strong></div>
            <div class="weui-dialog__bd">确定要删除吗？
            </div>
            <div class="weui-dialog__ft">
                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default">取消</a>
                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">确定</a>
            </div>
        </div>
	</div>
	<div id="dialog2" style="display:none;">
	    <div class="weui-mask"></div>
        <div class="weui-dialog">
            <div class="weui-dialog__hd"><strong class="weui-dialog__title">操作提示</strong></div>
            <div class="weui-dialog__bd" id="dialog2_msg">
            </div>
            <div class="weui-dialog__ft">
                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary" id="dialog2_but">好的</a>
            </div>
        </div>
	</div>

    <?php if($menu=='BO_CASC_HR_YGRS'){ ?>
    <div style="margin-top:10px;height:90px;text-align:center">
        <div class="img_wrap" >
            <?php if($zp_img){ ?>
            <img id="ygpic" style="width:100px;height:100px;border-radius:50px;" src="<?php echo $zp_img; ?>" alt="">
            <?php }else{ ?>
            <img id="ygpic" style="width:100px;height:100px;border-radius:50px;" src="__PUBLIC__/User/uploads/images/default.jpg" alt="">
            <?php } ?>
        </div>
    </div>
    <?php } ?>
    <!--<script src="__PUBLIC__/User/newjs/custom.js" type="text/javascript"></script>-->
</body>
</html>